﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefStoretake" :model="stateStoretake.vmModel" label-width="100px">
      <el-row>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_MaterialId_FormItem" prop="Entity.MaterialId" :label="$t('message.autotrans._Model_Storetake_Material')">
            <el-select v-model="stateStoretake.vmModel.Entity.MaterialId" clearable>
               <el-option v-for="item in stateStoretake.AllMaterials" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_MaterialName_FormItem" prop="Entity.MaterialName" :label="$t('message.autotrans._Model_Storetake_MaterialName')">
            <el-input v-model="stateStoretake.vmModel.Entity.MaterialName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_SheetId_FormItem" prop="Entity.SheetId" :label="$t('message.autotrans._Model_Storetake_Sheet')">
            <el-select v-model="stateStoretake.vmModel.Entity.SheetId" clearable>
               <el-option v-for="item in stateStoretake.AllSheets" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_SheetCode_FormItem" prop="Entity.SheetCode" :label="$t('message.autotrans._Model_Storetake_SheetCode')">
            <el-input v-model="stateStoretake.vmModel.Entity.SheetCode" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_ExpectedQty_FormItem" prop="Entity.ExpectedQty" :label="$t('message.autotrans._Model_Storetake_ExpectedQty')">
            <el-input v-model="stateStoretake.vmModel.Entity.ExpectedQty" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_CountedQty_FormItem" prop="Entity.CountedQty" :label="$t('message.autotrans._Model_Storetake_CountedQty')">
            <el-input v-model="stateStoretake.vmModel.Entity.CountedQty" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_VarianceQty_FormItem" prop="Entity.VarianceQty" :label="$t('message.autotrans._Model_Storetake_VarianceQty')">
            <el-input v-model="stateStoretake.vmModel.Entity.VarianceQty" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_StocktakeDate_FormItem" prop="Entity.StocktakeDate" :label="$t('message.autotrans._Model_Storetake_StocktakeDate')">
            <el-date-picker v-model="stateStoretake.vmModel.Entity.StocktakeDate" type='date' clearable></el-date-picker>
        </el-form-item>

        </el-col>
      </el-row>

      <div style="text-align:right;">
        <WtmButton @click="onSubmitStoretake"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

        <WtmButton @click="onCloseStoretake"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageWmsManagementStoretakeCreate;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { storetakeApi } from '/@/api/wmsmanagement/storetake';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefStoretake = ref();
const stateStoretake = reactive({
    vmModel: {
	  Entity:{
        MaterialId: null,
        MaterialName: '',
        SheetId: null,
        SheetCode: null,
        ExpectedQty: null,
        CountedQty: null,
        VarianceQty: null,
        StocktakeDate: undefined,
      },

	},
    
    AllMaterials: [] as any[],
    AllSheets: [] as any[],
});

// 取消
const onCloseStoretake = () => {
    closeDialog();
};

// 提交
const onSubmitStoretake = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefStoretake.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            storetakeApi().add(stateStoretake.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};

// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/WmsManagement/Storetake/GetMaterialDocs',[],false).then(x=>{stateStoretake.AllMaterials = x});
    other.getSelectList('/api/WmsManagement/Storetake/GetStoretakeSheets',[],false).then(x=>{stateStoretake.AllSheets = x});
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

